import { getCart } from 'network/cart'

const state = () => ({
  cartCount: 0
})
const mutations = {
  ADDCART(state, payload) {
    state.cartCount = payload.count
  },
  RESETNUM(state) {
    state.cartCount = 0
  }
}
const actions = {
  async updateCart({ commit }) {
    const res = await getCart()
    commit('ADDCART', { count: res.data.length || 0 })
  }
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
